import java.util.HashMap;
import java.util.LinkedList;


class Concat extends Expr {

    private Expr expr1,  expr2;

    public Concat(Expr op1, Expr op2) {
        expr1 = op1;
        expr2 = op2;
    }

    public Element eval(HashMap<String, Element> nametable, HashMap<String, Proc> functiontable, LinkedList var) {
        Element val1 = expr1.eval(nametable, functiontable, var);
		Element val2 = expr2.eval(nametable, functiontable, var);
		
        if (!val1.isList() || !val2.isList()) {
        	throw new IllegalArgumentException("Parse error. Expression does not evaluate to a list.");
        }
        
        Element list1 = val1.clone();
        Element list2 = val2.clone();
        Sequence seq = new Sequence();
        
        seq.getElements().addAll(list1.getListValue().getSequence().getElements());
        seq.getElements().addAll(list2.getListValue().getSequence().getElements());
		
        ElementList elementList = new ElementList(seq);
        
        return new Element(elementList);
    }
}